package com.smart_campus.activiti.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.smart_campus.activiti.vo.AskforleaveVo;
import com.smart_campus.sys.common.DataGridView;
import com.smart_campus.sys.domain.User;
import org.activiti.engine.task.Task;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import com.smart_campus.activiti.mapper.AskforleaveMapper;
import com.smart_campus.activiti.domain.Askforleave;
import com.smart_campus.activiti.service.AskforleaveService;

import java.util.List;

/**
*   @aytgor 陈鹏
*   @date 2020/6/28 15:14
*
*/
@Service
public class AskforleaveServiceImpl implements AskforleaveService{

    @Resource
    private AskforleaveMapper askforleaveMapper;

    //@CacheEvict 删除的注解通过对象id在redis中删除数据
    @CacheEvict(cacheNames = "com.smart_campus.activiti.service.impl.AskforleaveServiceImpl",key = "#activitiId")
    @Override
    public int deleteByPrimaryKey(Integer activitiId) {
        return askforleaveMapper.deleteByPrimaryKey(activitiId);
    }

    //@CachePut 要返回对象 添加通过reids主键回填的id来在redis创建对应id的对象数据
    @CachePut(cacheNames = "com.smart_campus.activiti.service.impl.AskforleaveServiceImpl",key = "#result.activitiId")
    @Override
    public Askforleave insert(Askforleave record) {
        askforleaveMapper.insert(record);
        return record;
    }

    //@CachePut 要返回对象 添加通过reids主键回填的id来在redis创建对应id的对象数据
    @CachePut(cacheNames = "com.smart_campus.activiti.service.impl.AskforleaveServiceImpl",key = "#result.activitiId")
    @Override
    public Askforleave insertSelective(Askforleave record) {
        askforleaveMapper.insertSelective(record);
        return record;
    }

    //@Cacheable 返回对象 通过对象id在redis中创建对象保存,方便下次使用
    @Cacheable(cacheNames ="com.smart_campus.activiti.service.impl.AskforleaveServiceImpl",key = "#activitiId")
    @Override
    public Askforleave selectByPrimaryKey(Integer activitiId) {
        return askforleaveMapper.selectByPrimaryKey(activitiId);
    }

    @Override
    public int updateByPrimaryKeySelective(Askforleave record) {
        return askforleaveMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public int updateByPrimaryKey(Askforleave record) {
        return askforleaveMapper.updateByPrimaryKey(record);
    }

    @Override
    public String getDeanOfStudies() {
        return null;
    }

    @Override
    public String getPresident() {
        return null;
    }

    @Override
    public List<Integer> getUserRole(User user) {
        return askforleaveMapper.getUserRole(user);
    }

    @Override
    public AskforleaveVo getAskforleave(Integer id) {
        return askforleaveMapper.getAskforleave(id);
    }

    @Override
    public DataGridView LookMylEAVE(AskforleaveVo askforleaveVo) {
        Page<Object> page = PageHelper.startPage(askforleaveVo.getPage(), askforleaveVo.getLimit());//分页数据格式
        return new DataGridView(page.getTotal(),askforleaveMapper.LookMylEAVE(askforleaveVo.getActivitiName()));
    }

}
